home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8378 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.0 KB  |  40 lines

  1. Path: newsfeed.internetmci.com!gatech!gt-news!news
  2. From: Darin Heuermann <gt1792a@prism.gatech.edu>
  3. Newsgroups: comp.lang.c++
  4. Subject: new and delete with arrays
  5. Date: 17 Feb 1996 13:38:18 GMT
  6. Organization: Virtual Software
  7. Message-ID: <4g4loa$i1l@mordred.gatech.edu>
  8. NNTP-Posting-Host: felix.cc.gatech.edu
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
  13.  
  14. When I allocate an array of classes with delete, should delete call all of 
  15. the instances' destructors?  Here is an example of what I mean.
  16.  
  17. //**********************************************
  18.  
  19. class MYCLASS {
  20. public:
  21.    MYCLASS(void);
  22.    ~MYCLASS(void);
  23. } // MYCLASS
  24.  
  25. MYCLASS *myClass;
  26.  
  27. myClass = new MYCLASS[10];
  28. delete myClass;
  29.  
  30. //**********************************************
  31.  
  32. I would expect all 10 instances to call ~MYCLASS() when delete myClass is 
  33. called, but only the first instance's destructor is being called.  Is the 
  34. a bug in the compiler or is this how it's supposed to work?
  35.  
  36. -- Darin Heuermann
  37. -- Virtual Software
  38.  
  39.  
  40.